Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access data on an array-only CBOR object? #82

Open
douglasg14b opened this issue Jan 19, 2025 · 2 comments
Open

How to access data on an array-only CBOR object? #82

douglasg14b opened this issue Jan 19, 2025 · 2 comments

Comments

@douglasg14b
Copy link

douglasg14b commented Jan 19, 2025

Access to values just throws exceptions: Not A Map

Image

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>
];
@douglasg14b
Copy link
Author

writing it as JSON works though, then using JSON.Net to further parse is effective.

Though undesirably slow.

@peteroupc
Copy link
Owner

peteroupc commented Jan 19, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants