master
Jason Staten 2 years ago
commit 73b1c4d252

@ -0,0 +1,69 @@
# Proto
## Parse a custom protocol format
Your payment processing application must interface with an old-school mainframe format that we've named "MPS7".
This means consuming a proprietary binary protocol format that no one on your team is familiar with yet.
## Task
You must write a program that reads in a transaction log and parses it. The transaction log will be named `txnlog.dat` and be in the same directory as your program. A sample `txnlog.dat` file is provided for you. The log should be parsed according to the specification in the **Notes** section below. Your program must answer the following 5 questions:
- What is the total amount in dollars of credits?
- What is the total amount in dollars of debits?
- How many autopays were started?
- How many autopays were ended?
- What is balance of user ID 2456938384156277127?
Your program must output the answers in the format below. For example, if your program determined that the
answer for each question was zero, your program would output:
```
total credit amount=0.00
total debit amount=0.00
autopays started=0
autopays ended=0
balance for user 2456938384156277127=0.00
```
You must supply your source code as part of your answer. Write your code in your
best programming language. We'll want to compile your code from source and run it from a Unix-like command line, so please include the complete instructions for doing so in a COMMENTS file.
## Notes
Because `txnlog.dat` is a binary file, it can't be read by a normal text editor like sublime or vim.
Instead, you'll need to read it programmatically and parse the data you read in from there.
This is how the transaction log is structured:
Header:
| 4 byte magic string "MPS7" | 1 byte version | 4 byte (uint32) # of records |
The header contains the canonical information about how the records should be processed. Be sure to validate the magic string from the header to ensure you're parsing the correct file format.
Note: there are fewer than 100 records in the sample `txnlog.dat`, this is not true of all transaction logs though.
Record:
| 1 byte record type enum | 4 byte (uint32) Unix timestamp | 8 byte (uint64) user ID |
Record type enum:
- 0x00: Debit
- 0x01: Credit
- 0x02: StartAutopay
- 0x03: EndAutopay
For Debit and Credit record types, there is an additional field, an 8 byte
(float64) amount in dollars, at the end of the record.
All multi-byte fields are encoded in network byte order.
The first record in the file, when fully parsed, will have these values:
| Record type | Unix timestamp | user ID | amount in dollars |
| ----------- | -------------- | ------------------- | ----------------- |
| 'Debit' | 1393108945 | 4136353673894269217 | 604.274335557087 |

@ -0,0 +1,42 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1662019588,
"narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2da64a81275b68fdad38af669afeda43d401e94b",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

@ -0,0 +1,39 @@
{
description = "TodoMVC in Go";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem (system:
let
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
version = builtins.substring 0 8 lastModifiedDate;
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
go = prev.go_1_19;
buildGoModule = prev.buildGo118Module;
})
];
};
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ go gopls gotools go-tools golangci-lint];
};
defaultPackage = pkgs.buildGoModule {
pname = "todogo";
inherit version;
src = ./.;
vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
};
});
}

Binary file not shown.
Loading…
Cancel
Save