How to access data on an array-only CBOR object?
Access to values just throws exceptions: Not A Map
This is CBOR data that is just arrays of arrays, it's not my data type, it's from a 3rd party. I did not seem to have issue parsing it with python or JS available libs, so I assume I may need to access this in some specific way??
This is effectively the schema of the CBOR encoded data, written in typescript, with WrrRawReqResV1 being the entire encoded object.
export type WrrHeader = [
key: string,
value: Buffer<ArrayBuffer>
]
export type WrrRawRequestV1 = [
requestTimeStamp: number,
requestMethod: string,
requestURL: string,
requestHeaders: WrrHeader[],
isRequestComplete: boolean,
requestBody: Uint8Array
];
export type WrrRawResponseV1 = null | [
responseTimeStamp: number,
responseStatusCode: number,
responseReason: string,
responseHeaders: WrrHeader[],
isResponseComplete: boolean,
responseBody: Uint8Array
];
export type WrrRawReqResV1 = [
format: "WEBREQRES/1",
agent: string,
protocol: string,
request: WrrRawRequestV1,
response: WrrRawResponseV1,
endTimeStamp: number,
optionalData: Record<string, unknown>
];
writing it as JSON works though, then using JSON.Net to further parse is effective.
Though undesirably slow.
I could not reproduce the error with the following code:
[Test]
public void TestArrayIndexing() {
CBORObject cbor=CBORObject.NewArray().Add(0).Add(1).Add(2);
Assert.AreEqual(0, cbor[0].AsInt32());
Assert.AreEqual(1, cbor[1].AsInt32());
Assert.AreEqual(2, cbor[2].AsInt32());
}
You should post a minimal CBOR example that demonstrates the issue you mention, as well as the version of the CBOR library you are using.
Do you still have this issue?
Sorry, yes. Here is an example (The GZip archive contains 1 CBOR file)
014128685_1737250888584_GET_89d7_C304C_status.openai.com_0.gz
I could not reproduce the issue with the following code:
// 'fn' is the name of the CBOR file at issue
byte[] bytes=System.IO.File.ReadAllBytes(fn);
CBORObject cbor=CBORObject.DecodeFromBytes(bytes);
Console.WriteLine(cbor[0]);
Console.WriteLine(cbor[1]);
Console.WriteLine(cbor[2]);
Console.WriteLine(cbor[3][0]);
Console.WriteLine(cbor[4][0]);
Console.WriteLine(cbor[5]);
What version of the CBOR library are you using? Could the problem lie in the IDE rather than your source code?
In the best case, you should provide a minimal example — as well as the minimal source code — that demonstrates your issue.